#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import (
    request,
    abort,
    current_app
)

from flask.views import View
from spider.lib.utils import check_mobile_request
from spider.utils.misc import get_default_logger

logger = get_default_logger()


class BaseView(View):
    methods = ['GET', 'POST']
    is_mobile = False
    template_name = 'web/scrm_pc_seo/{template}'
    common_data = dict(
    )

    def dispatch_request(self, *args, **kwargs):
        request_method = request.method
        ua = request.headers.get('User-Agent', '')
        self.is_mobile = check_mobile_request(ua)
        if self.is_mobile:
            self.template_name = 'web/scrm_mobile_seo/{template}'
        else:
            self.template_name = 'web/scrm_pc_seo/{template}'
        method = getattr(self, request_method.lower())(*args, **kwargs)
        return method

    def get(self, *args, **kwargs):
        abort(405)

    def post(self, *args, **kwargs):
        abort(405)

    def head(self, *args, **kwargs):
        return ''
